﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BabyFood.Entities;
using BabyFood.Data;

public partial class AlbumVideo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            HienThiVideo();
            Pager1.CurrentIndex = 1;
            HienThiVideo2(Pager1.CurrentIndex);
            Session["Title"] = "Album Video";
        }
    }

    /// <summary>
    /// Hiển Thị Video
    /// </summary>
    private void HienThiVideo()
    {
        int TotalRows = 0;
        TList<Video> TList_TinTuc = DataRepository.VideoProvider.GetPaged("", "NgayCapNhat DESC", 0, 1, out TotalRows);
        dlVideo.DataSource = TList_TinTuc;
        dlVideo.DataBind();
    }

    /// <summary>
    /// Hiển Thị Sub Tin
    /// </summary>
    private void HienThiVideo2(int PageNo)
    {
        int TotalRows = 0;
        TList<Video> TList_TinTuc = DataRepository.VideoProvider.GetPaged("", "NgayCapNhat DESC", PageNo - 1, Pager1.PageSize, out TotalRows);
        dlVideoall2.DataSource = TList_TinTuc;
        dlVideoall2.DataBind();

        Pager1.ItemCount = TotalRows;
        H_PageCount.Value = Pager1.PageCount.ToString();
    }

    /// <summary>
    /// Handles ItemDataBound, Binds ExchangesTo to the Child DataList
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void dlFromTrades_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {

            DataListItem parentList = e.Item;
            Literal lit_Name = (Literal)parentList.FindControl("H_VideoId");
            string i = (lit_Name.Text).ToString();
            int j = Convert.ToInt32(i);
            int TotalRows = 0;
            TList<Video> TList_Video = DataRepository.VideoProvider.GetPaged("", "NgayCapNhat DESC", 0, 3, out TotalRows);
            DataList dlToTrades = (DataList)parentList.FindControl("dlvideoall");
            dlToTrades.DataSource = TList_Video;
            dlToTrades.DataBind();
            //TList<CommentVideo> TList_TinTucs = DataRepository.CommentVideoProvider.GetPaged("IdVideo = " + j, "", 0, 0, out TotalRows);
            // Retrieve the Parent List

            Label label1 = (Label)parentList.FindControl("lblComment");
            label1.Text = TotalRows.ToString();

            int ChiaSe = 0;
            //TList<Thich> TList_Thich = DataRepository.ThichProvider.GetPaged("IdTinTuc = " + j, "", 0, 0, out ChiaSe);
            // Retrieve the Parent List
            Label chiaselb = (Label)parentList.FindControl("lblChiaSe");
            if (chiaselb != null)
            chiaselb.Text = ChiaSe.ToString();
        }
    }

    protected void Pager1_Command(object sender, CommandEventArgs e)
    {
        try
        {
            int currnetPageIndex = Convert.ToInt32(e.CommandArgument);
            Pager1.CurrentIndex = currnetPageIndex;
            HienThiVideo2(Pager1.CurrentIndex);
        }
        catch (Exception ex)
        {
            Common.WriteLog("AlbumVideo.aspx.cs", "Pager1_Command()", ex.ToString());
        }
    }

    protected void cmdNext_Click(object sender, ImageClickEventArgs e)
    {
        if (Pager1.CurrentIndex < Convert.ToInt32(H_PageCount.Value))
        {
            Pager1.CurrentIndex = Pager1.CurrentIndex + 1;
            HienThiVideo2(Pager1.CurrentIndex);
        }
    }

    protected void cmdPrevious_Click(object sender, ImageClickEventArgs e)
    {
        if (Pager1.CurrentIndex > 1)
        {
            Pager1.CurrentIndex = Pager1.CurrentIndex - 1;
            HienThiVideo2(Pager1.CurrentIndex);
        }
    }


    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }

    public string GetLienKet()
    {
        return Common.sPathUpLienKet;
    }

    public string GetNgay(object ngayviet)
    {
        DateTime s = Convert.ToDateTime(ngayviet);
        string v = s.ToString("HH:mm | dd/MM/yyyy");
        return Common.StandardStringjquery(v);
    }
    public string GetNoiDung(object noidung)
    {
        string sub = Server.HtmlDecode((Convert.ToString(noidung)));
        return sub;
    }
}